/**
* \file DGVImage.h
*
* \brief This file defines the class for displaying images using only Qt.
* \author Shekhar S. Chandra, 2008
*
* This file is part of DGV Library.
*
* DGV is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* DGV is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with DGV.  If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef DGVIMAGE_H
#define DGVIMAGE_H

#include <QtGui/QLabel> //For Base Class
#include <QtGui/QtGui>

#include "DGVBlitzArrayCaster.h"
#include "DGVTable.h" //also includes DGVAnimate, DGVAliases, DGVPlot

/*!
    \class DGVImage
    \brief This class represents the DGV Image Display object. WORK IN PROGESS.

    The class represents the DGV Image Display object using the Qt Library. It handles the elements necessary for Image Display and subsequent operations on images (such as transforms etc.).
*/
class DGV_EXPORT DGVImage : public QLabel
{
    Q_OBJECT

public:
    /*!
        \fn DGVImage::DGVImage(QWidget * parent = 0)
        \brief The standard constructor
    */
    DGVImage(QWidget *parent = 0);
    /*!
        \fn DGVImage::DGVImage(Array<imageType,2> &data, QWidget *parent = 0)
        \brief Overloaded constructor
    */
    DGVImage(Array<imageType,2> &data, QWidget *parent = 0);
    /*!
        \fn DGVImage::~DGVImage()
        \brief The standard destructor
    */
    virtual ~DGVImage();
    /*!
        \fn DGVImage::setName(QString filename)
        \brief Set the name of the image.
    */
    void setName(QString filename);

    /*!
        \fn DGVImage::openImage(QString filename)
        \brief Opens image with filename.
    */
    bool openImage(QString filename);
    /*!
        \fn DGVImage::linkResult(DGVImage *result)
        \brief The standard destructor
    */
    void linkResult(DGVImage *result);
    /*!
        \fn DGVImage::linkResult(DGVImage &result)
        \brief The standard destructor
    */
    inline DGVImage* getResult()
    {
        return resultImage;
    }
    /*!
        \fn DGVImage::setPixmap(const QPixmap &pix)
        \brief The standard destructor
    */
    virtual void setPixmap(const QPixmap &pix);
    virtual void setPixmap(const Array<imageType,2> &bins);
    /*!
        \fn DGVImage::dataPtr()
        \brief Pointer to the Blitz++ data held
    */
    inline Array<imageType,2>* dataPtr()
    {
        return &imageData;
    }
    /*!
        \fn DGVImage::data()
        \brief Blitz++ Array data held
    */
    inline Array<imageType,2>& data()
    {
        return imageData;
    }
    /*!
        \fn DGVImage::strippedName()
        \brief Returns the stripped (path removed) name of the image.
	*/
	QString strippedName();
	/*!
        \fn DGVImage::strippedNamePrefix()
        \brief Returns the stripped (path removed) name of the image with "Image" prefix.
	*/
	QString strippedNamePrefix();

public slots:
    /*!
        \fn DGVImage::table()
        \brief Sets up table of the image data.
    */
    void table();
    /*!
        \fn DGVImage::updateData(int row, int col)
        \brief Updates the content of cell changed by user of table in the image data.
    */
    void updateData(int row, int col);
    /*!
        \fn DGVImage::refreshImage()
        \brief Updates the display of the of the image data.
    */
    void refreshImage();
    /*!
        \fn DGVImage::normGreyscale()
        \brief Normalizes the greyscale so that the whole range of greyscale values are used in the
        display of the of the image data.
    */
    void normGreyscale();
    /*!
        \fn DGVImage::setInterpolation(bool interpolation)
        \brief Sets whether to enable interpolation (i.e. anti-aliasing) for image display.
    */
    void setInterpolation(bool interpolation);
    /*!
        \fn DGVImage::save()
        \brief Saves the image.
    */
    void save();


signals:
    /*!
        \fn DGVImage::resultAvailable(DGVImage *)
        \brief Send signal that Result is available for showing.
    */
    void resultAvailable(DGVImage *);
    /*!
        \fn DGVImage::tableAvailable(DGVTable *tableWidget)
        \brief Send signal that a table is available for showing.
    */
    void tableAvailable(DGVTable *tableWidget);

protected:
    QString name; //!< Name of the image (with full path)

    ///Context menu attributes
    QMenu *imageMenu; //!< Transform Right-Mouse Menu
    QAction *normGreyAct; //!< Action object for normalizing the greyscale in the display of an image.
    QAction *interpolateAct; //!< Transform Right-Mouse Menu
    QAction *tableAct; //!< Action object for displaying a table of data.
    //------------------
    QAction *refreshAct; //!< Action object for refreshing the display of an image.
    QAction *saveAct; //!< Saves window
    QAction *closeAct; //!< Closes window

    ///Image Data
    DGVImage *resultImage; //!< Points to where the result of any operation is to be kept.
    Array<imageType,2> imageData; //!< Contains the actual image data in full.
    DGVTable *dataTable; //!< Table form of data.
    bool loadComplete; //!< Keeps track when the image is loaded.

    DGVBlitzArrayCaster<imageType> Blitz; //!< Used to cast to and from Blitz arrays.

    ///Private Functions
    void createActions();
    void createConnections();
    void connectTable(DGVTable *child);
    /*!
    \fn DGVImage::contextMenuEvent(QContextMenuEvent *event)
    \brief The context menu setup member
    */
    void contextMenuEvent(QContextMenuEvent *event);
    void paintEvent(QPaintEvent *event);

private:
};

#endif // DGVIMAGE_H
